package xyz.xtt.asset.vo;

import org.hibernate.validator.constraints.Length;

import com.google.common.primitives.Longs;

import cn.hutool.core.util.IdUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import xyz.xtt.asset.entity.TblCollection;

/**
 * @author huqibo
 * @date 2024/11/19
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CreateCollectionRequestVo {
	@Schema(description = "风络名称")
	@NotBlank(message = "风格展示名称为必填项")
	@Length(max = 64, message = "风格名称限制为64长度")
	private String displayName;

	@Schema(description = "风格描述")
	@NotBlank(message = "风格描述为必填项")
	@Length(max = 100, message = "风格描述限制为100长度")
	private String description;

	@NotBlank(message = "风格封面url为必填项")
	@Schema(description = "风格封面图")
	@Length(max = 1024, message = "风格封面图限制为1024长度")
	private String coverImg;

	public String checkText() {
		return String.format("%s$%s", displayName, description);
	}

	public TblCollection convert(String uid) {
		return TblCollection
				.builder()
				.displayName(displayName)
				.description(description)
				.coverImg(coverImg)
				.appUserId(Longs.tryParse(uid))
				.id(IdUtil.getSnowflakeNextId())
				.serNo(IdUtil.getSnowflakeNextId())
				.topTime(0L)
				.createDatetime(System.currentTimeMillis())
				.lastModifyDatetime(System.currentTimeMillis())
				.build();
	}
}
